import { createBrowserRouter, redirect } from 'react-router-dom';

import AboutPage from './about/page';
import AppPage from './app/page';
import ComponentsPage from './components/page';
import CreatePostPage from './create-post/page';
import DemoPage from './demo/page';
import HomePage from './home/page';
import LoginPage from './login/page';
import RegisterPage from './register/page';
import DefaultLayout from '../layouts/DefaultLayout';

import meRoute from './me/route';
import Post$idPage from './posts/$id';

const router = createBrowserRouter([
  {
    path: '/',
    element: <DefaultLayout />,
    children: [
      { path: '', loader: () => redirect('/home') },
      { path: 'about', element: <AboutPage /> },
      { path: 'app', element: <AppPage /> },
      { path: 'components', element: <ComponentsPage /> },
      { path: 'create-post', element: <CreatePostPage /> },
      { path: 'demo', element: <DemoPage /> },
      { path: 'home', element: <HomePage /> },
      { path: 'login', element: <LoginPage /> },
      meRoute,
      { path: 'posts/:id', element: <Post$idPage /> },
      { path: 'register', element: <RegisterPage /> },
    ],
  },
]);

export default router;
